<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\App\Utils\CosClient;

use Overtrue\CosClient\Client;
use Overtrue\CosClient\Config;

class ObjectClient extends \Overtrue\CosClient\ObjectClient
{
    /**
     * @param array|\Overtrue\CosClient\Config $config
     *
     * @throws \Overtrue\CosClient\Exceptions\InvalidConfigException
     */
    public function __construct($config)
    {
        if (! $config instanceof Config) {
            $config = new Config($config);
        }

        parent::__construct($config);

        $verify = $config->get('guzzle.verify', true);
        $this->configureVerify($verify);
    }

    protected function configureVerify(bool $verify = true): Client
    {
        $options = $this->getHttpClientOptions();
        $options['verify'] = $verify;
        $this->setHttpClientOptions($options);
        return $this;
    }
}
